package com.jic.market.mapper.skill;

import com.jic.market.entity.skill.ActivitySkillGoodsConfig;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 秒杀活动商品基础配置表
 *
 * @author : seven
 * @version : v1.0.0
 * @email : 774329481@qq.com
 * @since : 2020-03-12 05:22:15
 */
@Repository
public interface ActivitySkillGoodsConfigMapper {

    long insert(ActivitySkillGoodsConfig activitySkillGoodsConfig);

    long delete(@Param("promotionId") String promotionId);

    long deleteById(@Param("id") Long id);

    long update(ActivitySkillGoodsConfig activitySkillGoodsConfig);

    ActivitySkillGoodsConfig queryByPrimaryKey(Long id);

    List<ActivitySkillGoodsConfig> query(ActivitySkillGoodsConfig activitySkillGoodsConfig);

    List<ActivitySkillGoodsConfig> queryPage(@Param("startIndex") int startIndex, @Param("limit") int limit, @Param("activitySkillGoodsConfig") ActivitySkillGoodsConfig activitySkillGoodsConfig);

    long queryPageCount(ActivitySkillGoodsConfig activitySkillGoodsConfig);

    @Update("update market_activity_skill_goods_config set delete_flag='1' where promotion_id=#{promotionId} and goods_id=#{goodsId} and time_id = #{timeId}")
    long deleteByPromotionIdAndGoodsId(@Param("promotionId") String promotionId, @Param("goodsId") String goodsId,@Param("timeId") String timeId);

    @Select({
            "<script>",
                "select * from market_activity_skill_goods_config where promotion_id=#{promotionId} and time_id=#{timeId} and delete_flag='0' and spu_id = '0' ",
                "<trim suffixOverrides=\"and\"> ",
                "<if test=\"start !=null and limit != null\"> ",
                "   limit #{start},#{limit}",
                "</if>  ",
                "</trim>",
            "</script>"
    })
    List<ActivitySkillGoodsConfig> queryGoodsInfoByTimeId(@Param("promotionId") String promotionId, @Param("timeId") String timeId, @Param("start") Integer start, @Param("limit") Integer limit);

    @Select("select count(1) from market_activity_skill_goods_config where promotion_id=#{promotionId} and time_id=#{skillTimeId} and delete_flag='0' and spu_id = '0'")
    Long queryGoodsInfoByTimeIdTotal(@Param("promotionId") String promotionId, @Param("skillTimeId") String skillTimeId);

    @Select("select count(1) from market_activity_skill_goods_config where promotion_id=#{promotionId} and time_id=#{skillTimeId} and delete_flag='0' and spu_id != '0'")
    Long queryGoodsInfoByTimeIdSkuTotal(@Param("promotionId") String promotionId, @Param("skillTimeId") String skillTimeId);

    @Update("update market_activity_skill_goods_config set delete_flag='1' where promotion_id=#{promotionId}" +
            " and merchant_id=#{merchantId}")
    long deleteGoodsByPromotionIdAndMerchantId(@Param("promotionId") String promotionId,
                                               @Param("merchantId") String merchantId);

    @Update("update market_activity_skill_goods_config set delete_flag='1' where promotion_id=#{promotionId}" +
            " and store_id=#{storeId}")
    long deleteGoodsByPromotionIdAndStoreId(@Param("promotionId") String promotionId,
                                                   @Param("storeId") String storeId);

    @Update("update market_activity_skill_goods_config set delete_flag='1' where promotion_id=#{promotionId}" +
            " and time_id=#{timeId}")
    long deleteGoodsByPromotionIdAndTimeId(@Param("promotionId") String promotionId,
                                                  @Param("timeId") String timeId);

    @Select("select count(1) from market_activity_skill_goods_config where promotion_id=#{promotionId}  and delete_flag='0'")
    Long querySkillGoodsTotal(@Param("promotionId") String promotionId);

    List<String> queryAllPromotionIdByThirdProductCode(@Param("thirdProductCode") String thirdProductCode);
}